//分类模块
import { findAllCategory } from '@/api/category'
import { topCategory } from '@/api/constants'
export default {
  namespaced: true,
  state() {
    return {
      // 分类信息整合
      list: topCategory.map(item => {
        return { name: item }
      })
    }
  },
  // 修改
  mutations: {
    show(state, item) {
      // console.log(state, item, '修改')
      const obj = state.list.find(v => v.id === item.id)
      obj.open = true
    },
    hide(state, item) {
      const obj = state.list.find(v => v.id === item.id)
      obj.open = false
    },
    setList(state, payload) {
      state.list = payload
    }
  },
  // 异步
  actions: {
    async findList(store) {
      const { result } = await findAllCategory()
      store.commit('setList', result.map(v =>
        ({ ...v, open: false })
      ))
    }
  }
}